//
//  OilAddRecordCell.m
//  阿帕
//
//  Created by mac on 2020/5/26.
//  Copyright © 2020 GCY. All rights reserved.
//

#import "OilAddRecordCell.h"

@interface OilAddRecordCell ()
@property (weak, nonatomic) IBOutlet UIImageView *leftImageView;
@property (weak, nonatomic) IBOutlet UILabel *oilTitleLabel;
@property (weak, nonatomic) IBOutlet UIView *lineView;
//@property (weak, nonatomic) IBOutlet UIView *infoBgView;
@property (weak, nonatomic) IBOutlet UILabel *repealLabel;
@property (strong, nonatomic) IBOutletCollection(UILabel) NSArray *textLabels;
@property (strong, nonatomic) IBOutletCollection(UILabel) NSArray *valueLabels;

@end

@implementation OilAddRecordCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    cut(_leftImageView, 3);
    
    _oilTitleLabel.textColor = Dark_TextColor;
    _lineView.backgroundColor = BackgroundColor;
    _repealLabel.backgroundColor = [UIColor cy_colorWithHexString:@"#FFEBE8"];
    _repealLabel.textColor = [UIColor cy_colorWithHexString:@"#FF3D1D"];
    cut(_repealLabel, 4);
    _repealLabel.hidden = YES;
    
    for (UILabel *valueLabel in _valueLabels) {
        valueLabel.adjustsFontSizeToFitWidth = YES;
    }
//
//    //油卡消费记录
//    NSArray *titleArr = @[@"分支机构", @"司机账号", @"加油时间", @"小票号", @"加油站", @"消耗油点", @"油卡余额"];
//    NSArray *valueArr = @[@"-", @"-", @"-", @"-", @"-", @"0", @"0"];
//
//    for (int i=0; i<titleArr.count; i++) {
//        UILabel *textLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 20*i, 60, 20)];
//        textLabel.textColor = Light_TextColor;
//        textLabel.font = font(14);
//        textLabel.text = titleArr[i];
//        textLabel.adjustsFontSizeToFitWidth = YES;
//        [_infoBgView addSubview:textLabel];
//
//        UILabel *valueLabel = [[UILabel alloc] initWithFrame:CGRectMake(70, 20*i, ScreenW-90-70, 20)];
//        valueLabel.tag = 100 + i;
//        valueLabel.textColor = Dark_TextColor;
//        valueLabel.font = font(14);
//        valueLabel.text = valueArr[i];
//        valueLabel.adjustsFontSizeToFitWidth = YES;
//        [_infoBgView addSubview:valueLabel];
//    }
}

- (void)setModel:(OilAddRecordModel *)model {
    
    _model = model;
    
    [_leftImageView sd_setImageWithURL:[NSURL URLWithString:model.driverHeadImg] placeholderImage:image(@"gcy_img_my_defultHead")];
    
    if (model.isDeleted == 1) {
        _repealLabel.hidden = NO;
    } else {
        _repealLabel.hidden = YES;
    }
    
    NSArray *names = @[];
    
    NSMutableArray *values = [[NSMutableArray alloc] initWithObjects:
     //分支机构
     [NSString nullToString:model.branchName],
     //司机账号
     CJStringWithFormat(@"%@(%@)",[NSString nullToString:model.driverName], [NSString nullToString:model.driverPhone]),
     //加油时间 or 充值时间
     [NSString nullToString:model.gmtCreated],
     //小票号 or 流水号
     [NSString nullToString:model.banks],
     //消耗油点 or 充值油点
     [NSString nullToString:CJStringWithFormat(@"%.2f", model.payPoint/100)],
     //油卡余额
     [NSString nullToString:CJStringWithFormat(@"%.2f", (CGFloat)model.driverBalanceOil/100)],
     nil
     ];
//    NSMutableArray *values = @[
//        //分支机构
//        [NSString nullToString:model.branchName],
//        //司机账号
//        CJStringWithFormat(@"%@(%@)", [NSString nullToString:model.driverName], [NSString nullToString:model.driverPhone]),
//        //加油时间 or 充值时间
//        [NSString nullToString:model.gmtCreated],
//        //小票号 or 流水号
//        [NSString nullToString:model.banks],
//        //消耗油点 or 充值油点
//        [NSString nullToString:CJStringWithFormat(@"%.2f", model.payPoint/100)],
//        //油卡余额
//        [NSString nullToString:CJStringWithFormat(@"%.2f", (CGFloat)model.driverBalanceOil/100)],
//    ];
    
    //if gasCode 为空, then 充值记录
    //else 不为空, then 消费记录
    if ([DCSpeedy isBlankString:model.gasCode]) {
        _oilTitleLabel.text = @"油卡充值记录";
        names = @[@"分支机构", @"司机账号", @"充值时间", @"流水号", @"充值油点", @"油卡余额"];
        
        UILabel *textLabel = _textLabels.lastObject;
        [textLabel setHidden:YES];
        
        UILabel *valueLabel = _valueLabels.lastObject;
        [valueLabel setHidden:YES];
    } else {
        _oilTitleLabel.text = @"油卡消费记录";
        names = @[@"分支机构", @"司机账号", @"加油时间", @"小票号", @"加油站", @"消耗油点", @"油卡余额"];
        [values insertObject:model.gasName atIndex:4];  //在小票号后插入"加油站"
        
        UILabel *textLabel = _textLabels.lastObject;
        [textLabel setHidden:NO];
        
        UILabel *valueLabel = _valueLabels.lastObject;
        [valueLabel setHidden:NO];
    }
    
    for (NSInteger i = 0; i < names.count; i++) {
        UILabel *textLabel = _textLabels[i];
        textLabel.text = names[i];
        
        UILabel *valueLabel = _valueLabels[i];
        valueLabel.text = values[i];
    }
    
    
//    for (int i=0; i<values.count; i++) {
//        UILabel *label = [self.contentView viewWithTag:100+i];
//        label.text = values[i];
//    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end
